// subpackage_volleyball/matches/matches.ts
Page({
  /**
   * 页面的初始数据
   */
  data: {
    upcomingMatches: [], // 即将开始和进行中的比赛
    finishedMatches: [],  // 已结束的比赛
    highlightMoments: [],  // 精彩瞬间
    teamIntroductions: [  // 新增：队伍介绍数据
      {
        teamId: 'team1',
        teamName: '北京队',
        introduction: '传统强队，多次夺冠。'
      },
      {
        teamId: 'team2',
        teamName: '上海队',
        introduction: '技术全面，战术多变。'
      },
      {
        teamId: 'team3',
        teamName: '广东队',
        introduction: '近年崛起，年轻球员为主。'
      },
      {
        teamId: 'team4',
        teamName: '江苏队',
        introduction: '进攻犀利，防守稳固。'
      },
      {
        teamId: 'team5',
        teamName: '浙江队',
        introduction: '打法灵活，擅长快攻。'
      },
      {
        teamId: 'team6',
        teamName: '福建队',
        introduction: '顽强拼搏，进步显著。'
      }
    ]
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad() {
    this.loadMatchData();
  },

  /**
   * 加载赛事数据
   */
  loadMatchData() {
    // 实际项目中，这里应该调用API获取数据
    const mockMatches = [
      {
        matchId: '1001',
        date: '2023-11-15',
        time: '15:00',
        homeTeam: '北京队',
        awayTeam: '上海队',
        homeLogo: '/images/teams/beijing.png',
        awayLogo: '/images/teams/shanghai.png',
        venue: '国家体育馆',
        status: 'upcoming'
      },
      {
        matchId: '1002',
        date: '2023-11-16',
        time: '14:30',
        homeTeam: '广东队',
        awayTeam: '江苏队',
        homeLogo: '/images/teams/guangdong.png',
        awayLogo: '/images/teams/jiangsu.png',
        venue: '广州体育中心',
        status: 'upcoming'
      },
      {
        matchId: '1003',
        date: '2023-11-12',
        time: '16:00',
        homeTeam: '辽宁队',
        awayTeam: '山东队',
        homeLogo: '/images/teams/liaoning.png',
        awayLogo: '/images/teams/shandong.png',
        venue: '沈阳体育馆',
        status: 'finished',
        homeScore: '3',
        awayScore: '1',
        mvp: '张三(辽宁队)'  // 新增MVP信息
      },
      {
        matchId: '1004',
        date: '2023-11-14',
        time: '15:30',
        homeTeam: '浙江队',
        awayTeam: '福建队',
        homeLogo: '/images/teams/zhejiang.png',
        awayLogo: '/images/teams/fujian.png',
        venue: '杭州体育中心',
        status: 'ongoing'
      },
      {
        matchId: '1005',
        date: '2023-11-10',
        time: '14:00',
        homeTeam: '四川队',
        awayTeam: '湖北队',
        homeLogo: '/images/teams/sichuan.png',
        awayLogo: '/images/teams/hubei.png',
        venue: '成都体育中心',
        status: 'finished',
        homeScore: '2',
        awayScore: '3',
        mvp: '李四(湖北队)'  // 新增MVP信息
      }
    ];

    // 分离即将开始/进行中和已结束的比赛
    const upcomingMatches = mockMatches.filter(match => match.status === 'upcoming' || match.status === 'ongoing');
    const finishedMatches = mockMatches.filter(match => match.status === 'finished');

    // 模拟精彩瞬间数据
    const highlightMoments = [
      {
        id: 'h1',
        title: '扣球得分',
        description: '辽宁队3号球员精彩扣球',
        image: '/static/image/images.png',
        matchId: '1003',
        date: '2023-11-12'
      },
      {
        id: 'h2',
        title: '拦网成功',
        description: '山东队双人拦网阻止对手进攻',
        image: '/static/image/images.png',
        matchId: '1003',
        date: '2023-11-12'
      },
      {
        id: 'h3',
        title: '精准传球',
        description: '四川队二传手精准组织进攻',
        image: '/static/image/images.png',
        matchId: '1005',
        date: '2023-11-10'
      },
      {
        id: 'h4',
        title: '鱼跃救球',
        description: '湖北队自由人精彩救球',
        image: '/static/image/images.png',
        matchId: '1005',
        date: '2023-11-10'
      }
    ];

    this.setData({
      upcomingMatches,
      finishedMatches,
      highlightMoments
    });
  },

  /**
   * 跳转到队伍信息页面
   */
  navigateToTeam(e: WechatMiniprogram.TouchEvent) {
    const teamName = e.currentTarget.dataset.team as string;
    wx.navigateTo({
      url: `/subpackage_volleyball/team/team?teamName=${encodeURIComponent(teamName)}`
    });
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh() {
    this.loadMatchData();
    wx.stopPullDownRefresh();
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage() {
    return {
      title: '排球赛事',
      path: '/subpackage_volleyball/matches/matches'
    };
  }
});